<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class BaseModel extends Model
{

    /**
     * 获取当前时间
     *
     * @return int
     */
    public function freshTimestamp() {
        return time();
    }

    /**
     * 开启事务
     */
    public static function BeginTrans()
    {
        DB::beginTransaction();
    }

    /**
     * 提交事务
     */
    public static function CommitTrans()
    {
        DB::commit();
    }

    /**
     * 操作成功返回值函数
     * @param string $data 数据组
     * @param integer $code  状态码
     * @param string $msg  提示语
     * @return void
     */
    public static function result($data = "", $code = 200, $msg = 'OK')
    {
        return  [
            'code' => $code,
            'msg' => $msg,
            'data' => ($data ? $data : [])
        ];
    }
}
